﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using System.Data;
using System.Data.SqlClient;
using AutoBackupDatabase.ENT;

namespace AutoBackupDatabase.DAL
{
    public class DEPARTMENTDAL
    {
         private DbConnection conn;
         public DEPARTMENTDAL()
        {
            conn = new DbConnection();
        }

         public List<DEPARTMENTENT> GET_DEPARTMENT_ALL()
         {
             List<DEPARTMENTENT> List = new List<DEPARTMENTENT>();
             try
             {
                 string query = string.Format("exec GET_DEPARTMENT_ALL ");
                 DataTable ds = conn.executeGetQuery(query);
                
                 foreach (DataRow item in ds.Rows)
                 {
                     DEPARTMENTENT departmentent = new DEPARTMENTENT();
                     departmentent.DEPARTMENTID = item["DEPARTMENTID"].ToString();
                     departmentent.DEPARTMENTNAME = item["DEPARTMENTNAME"].ToString();
                     List.Add(departmentent);
                 }
                 return List;
             }
             catch (Exception)
             {

                 return List;
             }
            

             
         }
         public bool INSERTDEPARTMENT(DEPARTMENTENT ent)
         {
             string query = "exec  INSERTDEPARTMENT @DEPARTMENTID,@DEPARTMENTNAME";
             SqlParameter[] sqlParameters = new SqlParameter[2];
             sqlParameters[0] = new SqlParameter("@DEPARTMENTID", SqlDbType.VarChar);
             sqlParameters[0].Value = Convert.ToString(ent.DEPARTMENTID);
             sqlParameters[1] = new SqlParameter("@DEPARTMENTNAME", SqlDbType.NVarChar);
             sqlParameters[1].Value = Convert.ToString(ent.DEPARTMENTNAME);
             return conn.executeInsertQuery(query, sqlParameters);
         }
         public bool UPDATEDEPARTMENTBYDEPARTMENTID(DEPARTMENTENT ent)
         {
             string query = "exec  UPDATEDEPARTMENTBYDEPARTMENTID @DEPARTMENTID,@DEPARTMENTNAME";
             SqlParameter[] sqlParameters = new SqlParameter[2];
             sqlParameters[0] = new SqlParameter("@DEPARTMENTID", SqlDbType.VarChar);
             sqlParameters[0].Value = Convert.ToString(ent.DEPARTMENTID);
             sqlParameters[1] = new SqlParameter("@DEPARTMENTNAME", SqlDbType.NVarChar);
             sqlParameters[1].Value = Convert.ToString(ent.DEPARTMENTNAME);
             return conn.executeUpdateQuery(query, sqlParameters);
         }
         public bool DELTELEDEPARTMENTBYDEPARTMENTID(DEPARTMENTENT ent)
         {
             string query = "exec  DELTELEDEPARTMENTBYDEPARTMENTID @DEPARTMENTID";
             SqlParameter[] sqlParameters = new SqlParameter[1];
             sqlParameters[0] = new SqlParameter("@DEPARTMENTID", SqlDbType.VarChar);
             sqlParameters[0].Value = Convert.ToString(ent.DEPARTMENTID);
             return conn.executeDeleteQuery(query, sqlParameters);
         }
    }
}
